-- Leviathan (c) v.v.balashoff
local Class = require('leviathan/Class')

local Viewer = Class:derive('UIViewerSystem')

function Viewer:new(domain)
    self.name = 'ViewerSystem'
    self.domain = domain
end

function Viewer:update(dt)
    local domain = self.domain
    local viewer = nil -- entity with viewer component
    -- check is there any viewer component
    local ent = domain.entities
    for i = 1, #ent do
        local e = ent[i]
        local c = e:getComponent('ViewerComponent')
        if c then
            local canvas = c.source.buffer.canvas
            if not (c.buffer == canvas) then
                c.buffer = canvas
                c.entity.domain.changed = true
print('VIEWER: CHANGED')
            end
        end
    end
end

return Viewer
